var app = getApp();
var $ = require("../../utils/httpHelper.js")
var w = 0
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: 0,
    width:0,
    info:'',
    name:'',
    banner:[],
    topimgh: 0,
    latitude:'',
    longitude:'',
    markers: [],
    controls: []
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  controltap(e) {
    console.log(e.controlId)
    let that = this
    wx.openLocation({
      latitude: parseFloat(that.data.latitude) ,
      longitude: parseFloat(that.data.longitude) ,
      scale: 28
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        w = res.screenWidth - 50 - 35
        let carr = []
        let c = {
          id: 1,
          iconPath: '/assets/dianx.png',
          position: {
            left: w,
            top: 210,
            width: 50,
            height: 50
          },
          clickable: true
        }
        carr.push(c)
        self.setData({
          height: res.windowHeight - 50,
          width: res.screenWidth,
          controls: carr
        })
      }
    })
    if (!app.check_empty(options.id) && !app.check_empty(options.name)){
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        shop_id: options.id
      }
      $.httpPost("mendian_detail", params, (data, err) => {
        let mark = {
          iconPath: "/assets/weizhi.png",
          latitude: data.data.detail.latitude,
          longitude: data.data.detail.longitude,
        }
        let marks = []
        marks.push(mark)
        this.setData({
          info: data.data.detail,
          name: options.name,
          banner:data.data.banner,
          latitude: data.data.detail.latitude,
          longitude: data.data.detail.longitude,
          markers: marks
        })
        console.log(data.data.detail.latitude)
        
      })
    }

  },
  imageLoad: function (e) {
    let that = this
    this.setData({
      topimgh: app.fixImgW(e, that.data.width),
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("xila")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  callphone(e) {
    let num = e.currentTarget.dataset.num
    wx.makePhoneCall({
      phoneNumber: num
    })
  },


})